##################################################################
#                                                                #
#  Winpooch : Windows Watchdog                                   #
#  Copyright (C) 2004-2005  Benoit Blanchon                      #
#                                                                #
#  This program is free software; you can redistribute it        #
#  and/or modify it under the terms of the GNU General Public    #
#  License as published by the Free Software Foundation; either  #
#  version 2 of the License, or (at your option) any later       #
#  version.                                                      #
#                                                                #
#  This program is distributed in the hope that it will be       #
#  useful, but WITHOUT ANY WARRANTY; without even the implied    #
#  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       #
#  PURPOSE.  See the GNU General Public License for more         #
#  details.                                                      #
#                                                                #
#  You should have received a copy of the GNU General Public     #
#  License along with this program; if not, write to the Free    #
#  Software Foundation, Inc.,                                    #
#  675 Mass Ave, Cambridge, MA 02139, USA.                       #
#                                                                #
##################################################################

DEFINES = -DUNICODE -D_UNICODE
DEFINES += -D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0500 -DWINVER=0x0500

CFLAGS = -Wall -Werror -gcoff $(DEFINES)


#
# Programs needed
#
CC	= gcc
GREP	= grep -n
LD	= gcc
MKDEP	= gcc -MM $(CFLAGS)
MV	= mv -f
PNG2ICO = png2ico
RC	= windres $(DEFINES)
RM	= rm -f
SED	= sed
STRIP	= strip

#
# Application specific stuffs
#
APPLICATION = Winpooch
APPLICATION_BIN = $(APPLICATION).exe
APPLICATION_LDFLAGS = -mwindows
APPLICATION_LDLIBS = -lpsapi -lcomctl32 -lcomdlg32 -lmsimg32 -lfreeimage -lwinmm -lshlwapi -lwininet
APPLICATION_SRCS = \
	AboutWnd.c \
	Application.c \
	Assert.c \
	AskDlg.c \
	Condition.c \
	Config.c \
	ConfigWnd.c \
	DbgPrint.c \
	EventLog.c \
	Filter.c \
	FilterFile.c \
	FilterSet.c \
	FilterWnd.c \
	HistoryWnd.c \
	Language.c \
	LogFile.c \
	MainWnd.c \
	PicBtnCtl.c \
	ProcList.c \
	ProcListWnd.c \
	ProgPathDlg.c \
	Reason.c \
	Rule.c \
	RuleDlg.c \
	Scanner.c \
	SplashWnd.c \
	SpyServer.c \
	StringList.c \
	Strlcpy.c \
	TrayIcon.c \
	UpdWatcher.c \
	VirusDlg.c \
	Wildcards.c
APPLICATION_OBJS = $(patsubst %.c,%.o,$(APPLICATION_SRCS)) Resources.o libSpyDll.a

#
# Spy DLL specific stuffs
#
SPYDLL = SpyDll
SPYDLL_BIN = $(SPYDLL).dll
SPYDLL_IMPLIB = lib$(SPYDLL).a
SPYDLL_LDLIBS = -lpsapi -lws2_32 -limagehlp -lshlwapi -lntdll
SPYDLL_SRCS = \
	Assert.c \
	Condition.c \
	DbgPrint.c \
	Disasm.c \
	Hooks.c \
	HookFile.c \
	HookNet.c \
	HookReg.c \
	HookSys.c \
	Reason.c \
	SpyDll.c \
	SpyDllInt.c \
	Strlcpy.c \
	Wildcards.c
SPYDLL_OBJS = $(patsubst %.c,%.o,$(SPYDLL_SRCS))


all : $(APPLICATION_BIN) $(SPYDLL_BIN)

clean :
	$(RM) *.o *.a *.d *.c~ *.h~ *.rc~ *.pl~ Makefile~ README~ CHANGELOG~ FAQ~

strip : $(APPLICATION_BIN) $(SPYDLL_BIN)
	$(STRIP) $(APPLICATION_BIN)
	$(STRIP) $(SPYDLL_BIN)

todo :
	$(GREP) TODO *.c *.h *.rc

Version.h : *.c *.h *.rc
	perl BuildCounter.pl Version.h

$(APPLICATION_BIN) : $(APPLICATION_OBJS)
	$(LD) $(APPLICATION_LDFLAGS) $^ $(APPLICATION_LDLIBS) -o $@

$(SPYDLL_BIN) $(SPYDLL_IMPLIB) : $(SPYDLL_OBJS)
	$(LD) $(CFLAGS) -shared -o $(SPYDLL_BIN) $^ -Wl,--out-implib,$(SPYDLL_IMPLIB) $(SPYDLL_LDLIBS)

%.o : %.rc
	$(RC) -o $@ $<

%.d : %.c
	$(MKDEP) $< > $@.$$$$; \
	$(SED) 's,\($*\)\.o[ :]*,\1.o $@ : ,g'  $@.$$$$ > $@; \
	$(RM) $@.$$$$

#
# Static dependencies
#
Resources.o : Resources.h Version.h rsrc/*

#
# Automatic dependencies
#
-include $(APPLICATION_SRCS:.c=.d)
-include $(SPYDLL_SRCS:.c=.d)
